from django_redis import get_redis_connection


class MyRedis:
    def __init__(self):
        self.redis = get_redis_connection(alias='code')

    def set_str(self, key, value, time):
        return self.redis.setex(key, time, value)
    # 获取key
    def get_str(self, key):
        val = self.redis.get(key)
        if val:
            return val.decode('utf-8')
        else:
            return None
    # 设置一个参数可以带增量的
    def hotadd(self, key, word):
        return self.redis.zincrby(key, 1, word)
    # 获取前10秒
    def hotget(self, key, num):
        return self.redis.zrevrange(key, 0, num)
    #存储普通字符串
    def setstrno(self,key,value):
        return self.redis.set(key,value)
    #删除指定的key
    def delkey(self,key):
        return self.redis.delete(key)



redistoll = MyRedis()
